package game.controlling;
import java.util.Vector;

import tools.Help;
import tools.Point;
/**
 * A class that is directly connected to the Window/Renderer classes and contains the pressed keys / buttons in that window. Keeps track of buttons/keys that are pressed, touched or released. (pressed = true as long as the button/key is held down.) (touched = true in the frame the button has been pressed the first time, not for the subsequent frames) (released = true in the frame after the button was pressed)
 * 
 * @author toni
 * 
 */
public class KeyListener {
	public Vector<Integer> keys, buttons;
	public Vector<Integer> cKeys, cButtons;
	public Vector<Integer> rKeys, rButtons;
	public Point mp;
	public KeyListener() {
		keys = new Vector<Integer>();
		buttons = new Vector<Integer>();
		cKeys = new Vector<Integer>();
		cButtons = new Vector<Integer>();
		rKeys = new Vector<Integer>();
		rButtons = new Vector<Integer>();
		mp = new Point();
	}
	public void addKey(int eventKey, boolean b) {
		if (b) {
			keys.addElement(eventKey);
			cKeys.addElement(eventKey);
		}
		else {
			keys.removeElement(eventKey);
			rKeys.add(eventKey);
		}
	}
	public void addButton(int eventButton, boolean b) {
		if (b) {
			buttons.addElement(eventButton);
			cButtons.addElement(eventButton);
		}
		else {
			buttons.removeElement(eventButton);
			rButtons.add(eventButton);
		}
	}
	public boolean isButtonReleased(int button) {
		for (int i : rButtons) {
			if (i == button)
				return true;
		}
		return false;
	}
	public void clear() {
		cKeys.clear();
		cButtons.clear();
		rKeys.clear();
		rButtons.clear();
	}
	public void setMouseX(float x) {
		mp.x = x;
	}
	public void setMouseY(float y) {
		mp.y = y;
	}
	public boolean isButtonPressed(int button) {
		for (int i : buttons) {
			if (i == button)
				return true;
		}
		return false;
	}
	public boolean isButtonTouched(int button) {
		for (int i : cButtons) {
			if (i == button)
				return true;
		}
		return false;
	}
	public boolean isKeyTouched(int key) {
		for (int i : cKeys) {
			if (i == key)
				return true;
		}
		return false;
	}
	public boolean isKeyPressed(int key) {
		for (int i : keys) {
			if (i == key)
				return true;
		}
		return false;
	}
	public boolean isKeyReleased(int key) {
		for (int i : rKeys) {
			if (i == key)
				return true;
		}
		return false;
	}
}
